package com.person.android.widgets;

import android.app.AlertDialog;
import android.content.Context;
import android.os.Bundle;
import android.widget.TextView;

import com.person.android.formatts.R;

/**
 * Created by zhaokang on 2015/12/1.
 */
public class CustomAlertDialog extends AlertDialog {

    private int mMax;
    private int width;
    private int mProgressVal;
    private boolean mHasStarted;
    private TextView update_text;
    private RoundProgressBar mProgress;

    public CustomAlertDialog(Context context) {
        super(context);
    }

    protected CustomAlertDialog(Context context, int theme) {
        super(context, theme);
    }

    protected CustomAlertDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_transform);
        initData();
    }

    private void initData() {
        mProgress = (RoundProgressBar) findViewById(R.id.roundProgressBar);
        width = (int) getContext().getResources().getDimension(R.dimen.dialog_height_width);
        mProgress.getLayoutParams().height = width;
        mProgress.getLayoutParams().width = width;
        mProgress.setTextSize(getContext().getResources().getDimension(R.dimen.dialog_text_size));
        update_text = (TextView) findViewById(R.id.transform_text);
    }

    public void setProgress(int value) {
        if (mHasStarted) {
            mProgress.setProgress(value);
        } else {
            mProgressVal = value;
        }
    }

    public int getProgress() {
        if (mProgress != null) {
            return mProgress.getProgress();
        }
        return mProgressVal;
    }

    public void setMax(int max) {
        if (mProgress != null) {
            mProgress.setMax(max);
        } else {
            mMax = max;
        }
    }

    public int getMax() {
        if (mProgress != null) {
            return mProgress.getMax();
        }
        return mMax;
    }

    @Override
    public void onStart() {
        super.onStart();
        mHasStarted = true;
    }

    @Override
    protected void onStop() {
        super.onStop();
        mHasStarted = false;
    }

}
